package cuiyt.designpattern.observer.v2;

import cuiyt.designpattern.observer.v2.event.AlertChangeEvent;
import cuiyt.designpattern.observer.v2.event.DiningChangeEvent;
import cuiyt.designpattern.observer.v2.vo.Event;
import cuiyt.designpattern.observer.v2.vo.Student;
import cuiyt.designpattern.observer.v2.vo.Teacher;

public class Test {

    /**
     * 被观察者：铃声
     * 观察者: 学生
     * 结果：铃声发生变化的时候学生做出相对应的动作
     * @param args
     */
    public static void main(String[] args) {

        ClassRoom classRoom = new ClassRoom();

        // 观察者
        Student cytStu = new Student("cyt");
        Student testStu = new Student("test");
        Teacher teacher = new Teacher("teacher");

        classRoom.addObserver(teacher);
        classRoom.addObserver(cytStu);
        classRoom.addObserver(testStu);

        // 被观察者
        AlertChangeEvent beginEvent = new AlertChangeEvent(new Event("上课啦"));
        // 发起事件
        classRoom.pubEvent(beginEvent);

        // 被观察者
        AlertChangeEvent stopEvent = new AlertChangeEvent(new Event("下课啦"));
        // 发起事件
        classRoom.pubEvent(stopEvent);

        // 被观察者
        DiningChangeEvent alertChangeEvent = new DiningChangeEvent(new Event("开饭啦"));
        // 发起事件
        classRoom.pubEvent(alertChangeEvent);

    }
}
